package HOANGTHANHCONG_SWING_BAI3;

import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class VIEW {
	CONTROLLER ctrl1 = new CONTROLLER();
	MODEL model1  = new MODEL();
	

	private JFrame frmngKTham;
	private JTextField txtName;
	private JTextField txtAge;
	private JTextField txtkq;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					VIEW window = new VIEW();
					window.frmngKTham.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public VIEW() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmngKTham = new JFrame();
		frmngKTham.setTitle("Đăng kí tham gia kết bạn");
		frmngKTham.setIconImage(Toolkit.getDefaultToolkit().getImage(VIEW.class.getResource("/HOANGTHANHCONG_SWING_Bai1/top_work_tree.png")));
		frmngKTham.setBounds(100, 100, 450, 300);
		frmngKTham.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmngKTham.getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Tên của bạn:");
		lblNewLabel.setBounds(10, 11, 87, 33);
		frmngKTham.getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Tuổi của bạn:");
		lblNewLabel_1.setBounds(10, 56, 100, 28);
		frmngKTham.getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Tình trạng hôn nhân: ");
		lblNewLabel_2.setBounds(10, 100, 124, 23);
		frmngKTham.getContentPane().add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("Giới tính:");
		lblNewLabel_3.setBounds(10, 145, 100, 14);
		frmngKTham.getContentPane().add(lblNewLabel_3);
		
		JLabel lblNewLabel_4 = new JLabel("Kết quả đăng kí: ");
		lblNewLabel_4.setBounds(10, 181, 100, 14);
		frmngKTham.getContentPane().add(lblNewLabel_4);
		
		txtName = new JTextField();
		txtName.setBounds(128, 14, 272, 27);
		frmngKTham.getContentPane().add(txtName);
		txtName.setColumns(10);
		
		txtAge = new JTextField();
		txtAge.setBounds(128, 60, 188, 20);
		frmngKTham.getContentPane().add(txtAge);
		txtAge.setColumns(10);
		
		final JComboBox cbbstt = new JComboBox();
		cbbstt.setModel(new DefaultComboBoxModel(new String[] {"", "Chưa có gia đình", "Đã có gia đình", "Li hôn"}));
		cbbstt.setBounds(128, 101, 188, 20);
		frmngKTham.getContentPane().add(cbbstt);
		
		final JComboBox cbbSex = new JComboBox();
		cbbSex.setModel(new DefaultComboBoxModel(new String[] {"", "Nam", "Nữ"}));
		cbbSex.setBounds(128, 142, 188, 20);
		frmngKTham.getContentPane().add(cbbSex);
		
		txtkq = new JTextField();
		txtkq.setBounds(128, 181, 272, 51);
		frmngKTham.getContentPane().add(txtkq);
		txtkq.setColumns(10);
		
		JButton btnđăngkí = new JButton("Đăng kí!");
		btnđăngkí.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				model1.setAge(Integer.parseInt(txtAge.getText()));
				model1.setName(txtName.getText());
				model1.setSTT(cbbstt.getSelectedIndex());
				model1.setSex(cbbSex.getSelectedIndex());
				if(model1.getName().isEmpty()){txtkq.setText("Chưa nhập tên");}
				else txtkq.setText(model1.getName()+"  " +ctrl1.xuli(model1));
			}
		});
		btnđăngkí.setBounds(335, 239, 89, 23);
		frmngKTham.getContentPane().add(btnđăngkí);
	}
}
